package com.dong.c03_channel;

import java.nio.ByteBuffer;
import java.nio.ReadOnlyBufferException;

/**
 * <h1>只读</h1>
 *  {@link ReadOnlyBufferException}
 * @author : dzj
 * @create: 2020-03-18 00:07
 */
public class P6_NIOByteBufferReadonly {
    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(64);
        for (int i = 0; i < 64; i++) {
            buffer.put((byte)i);
        }
        buffer.flip();
        ByteBuffer readOnlyBuffer = buffer.asReadOnlyBuffer();
        while (readOnlyBuffer.hasRemaining()) {
            System.out.println(readOnlyBuffer.get());
        }
        readOnlyBuffer.flip();
        readOnlyBuffer.put((byte)1);
    }
}
